<?php

namespace App\Http\Controllers\Common;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Session,DB;
use App\Http\ClassBox\globals;

class PublicController extends Controller
{
    //登陆页
    public function login()
    {
        return view('system.public.login');
    }

    //登录验证
    public function login_check(Request $request)
    {
        $username=trim($request->input('username'));//取得username
        $password=trim($request->input('password'));//取得password
        $validator=Validator::make(
            $request=array('username'=>$username,'password'=>md5(md5($password))),
            $rules=array(
                'username'=>'exists:use,Name,Del,1|required',
                'password'=>'exists:use,Pwd,Name,'.$username.'|required'
            ),
            $messages=array(
                'username.required'=>'用户名必须',
                'username.exists'=>'用户名错误或不存在',
                'password.required'=>'密码必须',
                'password.exists'=>'密码错误'
            )
        );
        if($validator->fails())
        {
            return redirect('login')->withErrors($validator);
        }
        return $username.'+'.$password;
    }

    //登出
    public function logout()
    {
        session::flush();
        return redirect('login');
    }

    //主页
    public function index()
    {
        session::put('user',DB::table('use')->where('id',1)->get());
        return session('user');
    }


    public function test()
    {
        return 1;
    }


}
